package com.ruoyi.crm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.Clue;
import com.ruoyi.crm.domain.vo.BusinessTrackRecordVo;
import com.ruoyi.crm.domain.vo.ContractVo;
import com.ruoyi.crm.domain.vo.GiveBackVo;
import com.ruoyi.crm.service.IBusinessService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/crm/business/track")
public class BusinessTrackRecordController extends BaseController {
    @Resource
    private IBusinessService businessService;

    /**
     *新增线索跟踪记录
     */
    @Log(title = "线索跟踪记录", businessType = BusinessType.UPDATE)
    @PostMapping
    public AjaxResult record(@RequestBody BusinessTrackRecordVo businessTrackRecordVo) {
        businessTrackRecordVo.setStatus(Clue.Status.TRACKING.getValue());
        return toAjax(businessService.updateBusiness(businessTrackRecordVo));
    }

    /**
     *踢回公海
     */
    @Log(title = "线索跟踪记录", businessType = BusinessType.UPDATE)
    @PutMapping("/giveBack")
    public AjaxResult giveBack(@RequestBody GiveBackVo giveBackVo) {
        return toAjax( businessService.giveBack(giveBackVo.getId()));
    }


    /**
     *批量捞取商机
     */
    @Log(title = "线索跟踪记录", businessType = BusinessType.INSERT)
    @PostMapping("/reset")
    public AjaxResult reset(@RequestBody List<GiveBackVo> giveBackVo) {
        return toAjax(businessService.resetList(giveBackVo));
    }


//    @Log(title = "线索跟踪记录", businessType = BusinessType.INSERT)
//    @PutMapping("/reset")
//    public AjaxResult reset(@RequestBody GiveBackVo giveBackVo) {
//        return toAjax(businessService.reset1(giveBackVo.getId()));
//    }


    /**
     *转客户
     */
    @Log(title = "线索跟踪记录", businessType = BusinessType.UPDATE)
    @PostMapping("/transform/{id}")
    public AjaxResult transform(@RequestBody ContractVo contractVo) {
        return toAjax(businessService.transform2Customer(contractVo));
    }

}
